//
//  setUpTableViewCell.m
//  FoodCorner
//
//  Created by lanou3g on 16/3/1.
//  Copyright © 2016年 zhangchao. All rights reserved.
//

#import "setUpTableViewCell.h"
#import "setUpModel.h"
@implementation setUpTableViewCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        //设置cell内部的子视图
        [self setSubviews];
    }
    return self;
}
/**
 添加cell内部的子视图
 */
- (void)setSubviews
{
    //底部照片
    self.backImagV = [[UIImageView alloc] init];
    
    UIImage *image = [UIImage imageNamed:@"setting-list-bg"];
    UIEdgeInsets dege = UIEdgeInsetsMake(0.2, 0,0.2, 0);
    self.backImagV.image = [image resizableImageWithCapInsets:dege resizingMode:UIImageResizingModeStretch];
    
    [self.contentView addSubview:_backImagV];
    
    //左侧图片
    self.leftImagV = [[UIImageView alloc] init];
    _leftImagV.clipsToBounds = YES;
    _leftImagV.userInteractionEnabled = YES;
    [self.contentView addSubview:_leftImagV];
    
    //中间文字Label
    self.lab = [[UILabel alloc] init];
    _lab.userInteractionEnabled = YES;
    [self.contentView addSubview:_lab];
    
    //右侧图片
    self.rightImagV = [[UIImageView alloc] init];
    self.rightImagV.contentMode = UIViewContentModeCenter;
    _rightImagV.clipsToBounds = YES;
    _rightImagV.userInteractionEnabled = YES;
    [self.contentView addSubview:_rightImagV];
    
}
/**
 model_cell的Setter方法中赋值
 */
-(void)setModel_cel:(setUpModel *)model_cel
{
    _model_cel = model_cel;
    //设置是否隐藏
    self.leftImagV.hidden = _model_cel.hiddenL;
    self.rightImagV.hidden = _model_cel.hiddenR;
    UIEdgeInsets dege = UIEdgeInsetsMake(0.2, 0,0.2, 0);
    self.backImagV.image = [self.model_cel.backImagV_image resizableImageWithCapInsets:dege resizingMode:UIImageResizingModeStretch];
    self.leftImagV.image = self.model_cel.leftImagV_image;
    self.rightImagV.image = self.model_cel.rightImagV;
    self.lab.text = self.model_cel.lab_text;
    UITableView *tabView = (UITableView *)self.superview.superview;
    tabView.rowHeight = self.model_cel.rowHegit;
    
}
/**
 设置每组内部子视图的具体内容
 */
//- (void)setValueInGroupOnCell
-(void)layoutSubviews
{
    //设置内部子视图的frame
    CGFloat margin = 5;
    CGFloat selfH = self.contentView.frame.size.height;
    
    CGFloat backX = 0;
    CGFloat backY = 0;
    CGFloat backW = self.contentView.frame.size.width;
    self.backImagV.frame = CGRectMake(backX, backY, backW, selfH);
    
    CGFloat leftX = margin;
    CGFloat leftY = margin;
    CGFloat leftW = selfH - 2*margin;
    CGFloat leftH = leftW;
    self.leftImagV.frame = CGRectMake(leftX, leftY, leftW, leftH);
    
    CGFloat labX = CGRectGetMaxX(self.leftImagV.frame) + margin;
    if (self.leftImagV.hidden) {//如果左侧照片隐藏lab的x偏移
        labX = 2*margin;
    }
    
    CGFloat labY = leftY;
    CGFloat labH = leftH;
    //lab的宽度根据lab上的文字自适应高度
    CGSize size_lab = [self.lab.text boundingRectWithSize:CGSizeMake(200, labH) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:17]} context:nil].size;
    CGFloat labW = size_lab.width;
    self.lab.frame = CGRectMake(labX, labY, labW, labH);
    
    CGFloat rightW = leftW;
    CGFloat rightX = self.frame.size.width - margin - rightW;
    CGFloat rightY = leftY;
    CGFloat rightH = rightW;
    self.rightImagV.frame = CGRectMake(rightX, rightY, rightW, rightH);
    
    [self.contentView setBackgroundColor:[UIColor whiteColor]];
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    
    
}



@end
